<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <p>子传父：将子组件的数据传给父组件</p>
        <p>传来的信息：{{info}}</p>
        <hr>
        <son @send="getData"></son>
    </div>
    <template id="son">
        <div>
            <input type="text" v-model="age">
            <button @click="post">传给父组件</button>
        </div>
    </template>
    <script src="../0511/js/vue.js"></script>
    <script>
        let vm = new Vue({
            el: '#app',
            data: {
                info: ''
            },
            methods: {
                getData(val) {
                    console.log(val);
                }
            },
            components: {
                son: {
                    template: '#son',
                    data() {
                        return {
                            msg: '学校要收书费（买游戏机），打钱',
                            age: 1
                        }
                    },
                    methods: {
                        post() {
                            // 子传父---发射自定义事件，携带的参数就是要传的数据
                            this.$emit('send', [this.msg, true, this.age]);
                        }
                    }
                }
            }
        })
    </script>
</body>

</html>